package VectorApproach;

import java.util.ArrayList;
import java.util.List;

import Application.ReadFileGenerateor;
import Application.TrajSplit;
import MyLoader.MyLoader;
import XmlLoader.FGObjProcess;
import XmlLoader.FGObjectTrajectoryStructure;

public class VRoadDetection {

	ArrayList<TrajVector> listTraj = null;
	ArrayList<VClusterBulk> listCluster = null;
	
	public VRoadDetection() {
		this.listTraj = new ArrayList<TrajVector>();
		this.listCluster = new ArrayList<VClusterBulk>();
	}
	
	public void ACT001_loadCluster(String filePath) {
		ArrayList<VClusterBulk> list = VClusterReader.loadFromFile(this.listTraj, filePath);
	}
	
	public void ACT002_loadRoadData(ArrayList<TrajVector> listTraj) {
		this.listTraj = listTraj;
	}
	
	public static void main(String[] args) {
		//generate list trajectory index
		System.out.println("Generate trajectory index file");
		new ReadFileGenerateor().ACT001_genFile(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2]));
										
		//load trajectory xml data
		System.out.println("Load trajectory xml file");
		FGObjProcess fgObj = new FGObjProcess(args[3]);
		List<String> list_objIndex = fgObj.ACT004_getStringList(args[0]);
		List<FGObjectTrajectoryStructure> listAll = new MyLoader().ACT001_getListOfObj(args[3], list_objIndex);
				
		//trajectory segmentation
		System.out.println("Trajectory segmentation");
		TrajSplit split = new TrajSplit(Integer.parseInt(args[8]));
		ArrayList<TrajVector> listTrajV = new ArrayList<TrajVector>();
		FGObjectTrajectoryStructure traj = null;
		int index = 0;
		while(index < listAll.size()) {
			traj = listAll.get(index);
			if(traj.GET002_nNumberOfPoint() > 2) {
				split.readPosition(traj);
				split.compress(split.Positions.get(0), split.Positions.get(split.Positions.size() - 1));
				int indexResult = 0;
				ArrayList<TrajVector> listResult = split.transfromVector(1000);
				while(indexResult < listResult.size()) {
					listTrajV.add(listResult.get(indexResult));
					indexResult = indexResult + 1;
				}
			}
			index = index + 1;
		}
	}
}
